<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head lang="pt">
	<title>Cadastro de Clientes</title>
</h:head>

<h:body lang="pt">
	<h:form id="form">
		<p:panel id="pnlCliente" header="Dados do Cliente" toggleable="true">
			<h:panelGrid id="pnlGridPCliente" columns="3" cellpadding="5"
				cellspacing="5">
				<h:outputLabel value="Nome" />
				<p:inputText id="edtNome" maxlength="100"
					title="Digite o nome do Cliente"
					value="#{clienteBean.cliente.nome}" required="true"
					requiredMessage="Campo obrigatório!" />
				<p:message showDetail="true" for="edtNome" />

				<h:outputLabel value="CPF" for="edtCpf" />
				<p:inputText id="edtCpf" title="Digite o cpf do cliente"
					value="#{clienteBean.cliente.CPF}" required="true"
					requiredMessage="Campo obrigatório!" />
				<p:message showDetail="true" for="edtCpf" />


				<h:outputLabel value="Limite" />
				<p:inputText id="edtLimite" maxlength="15"
					title="Digite o limite de compra do cliente"
					value="#{clienteBean.cliente.limite}">
				</p:inputText>
			</h:panelGrid>

			<p:commandButton value="OK" title="Grava o cliente"
				actionListener="#{clienteBean.salva()}"
				update=":form:pnlCliente,:form:pnlClientes" />
		</p:panel>

		<p:panel id="pnlClientes" header="Clientes cadastrados"
			toggleable="true">
			<p:dataTable id="tblClientes" value="#{clienteBean.clientes}"
				var="cliente" emptyMessage="Nenhum cliente encontrado">
				<p:column headerText="Nome">
					<h:outputText value="#{cliente.nome}" />
				</p:column>

				<p:column headerText="Cpf">
					<h:outputText value="#{cliente.CPF}">
						<f:convertNumber pattern="#,##000.000.000-00##" />
					</h:outputText>
				</p:column>

				<p:column headerText="Limite">
					<h:outputText value="#{cliente.limite}">
						<f:convertNumber pattern="#,##0.00##" />
					</h:outputText>
				</p:column>

				<p:column>
					<p:commandButton value="Alterar" title="Altera dados do cliente"
						icon="ui-icon-pencil"
						actionListener="#{clienteBean.altera(cliente)}" process="@this"
						update=":form:pnlCliente" />
				</p:column>
				
				<p:column>
					<p:commandButton value="Excluir" title="Exclui o  cliente"
						icon="ui-icon-trash"
						actionListener="#{clienteBean.exclui(cliente)}" process="@this"
						update=":form:pnlCliente,:form:pnlClientes" />
				</p:column>

			</p:dataTable>
		</p:panel>

	</h:form>
</h:body>

</html>